package data;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;


public class DataReader {
	String filename;
	BufferedReader file;
	boolean eof;
	int itemsRead;
	public DataReader(String f){
		filename = f;
		itemsRead = 0;
		eof = false;
		try{
			file = new BufferedReader(new FileReader(filename));
		}
		catch (FileNotFoundException f1){
			System.out.println("File "+filename+" not found");
			
		}
	}
	
	public synchronized void reset(){
		try{
			file.close();
		}
		catch (IOException f1){
			System.out.println("File "+filename+" could not be closed");
			
		}
		try{
			file = new BufferedReader(new FileReader(filename));
		}
		catch (FileNotFoundException f1){
			System.out.println("File "+filename+" not found");
			
		}
		itemsRead = 0;
		eof = false;
		
	}
	
	public synchronized String nextData(){
		try {
			String s = file.readLine();
			if (s == null) eof = true;
			else itemsRead++;
			return s;
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}
}
